package com.cn.hjsj.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


import net.sf.json.JSONObject;


/**
 * @author lcc
 *
 * 创建时间： 2017-2-24 下午2:42:08
 * 备注：检查参数工具类
 */
public class CheckUtil {
    //判断jsonstring
    public static Map<String,Object> NonEmpty_jsonstring(String jsonstring){
        Map<String, Object> map=new HashMap<String,Object>();
        if("".equals(jsonstring) || jsonstring==null) {map.put("ret","1"); map.put("code", 30000);map.put("message", "无请求数据");return map;}
        JSONObject object;
        try{
            object = JSONObject.fromObject(jsonstring);
        }catch (Exception ex){
            map.put("ret","1");
            map.put("code",20001);
            map.put("message","json" +"格式错误");
            return map;
        }
        if(!object.containsKey("app_key")){map.put("ret","1");map.put("code",20002);map.put("message","app_key不存在！");return map;}
       // if(!object.containsKey("app_sign")){map.put("ret","1");map.put("code",20003);map.put("message","app_sign不存在！");return map;}
       // if(!object.containsKey("parameter")){map.put("ret","1");map.put("code",20004);map.put("message","parameter不存在！");return map;}
     //   String app_key= Md5Util.GetMD5Code(Parameters.getParameters("app_key"));
       // if(!app_key.equals(object.get("app_key").toString())){map.put("ret","1");map.put("code",30001);map.put("message","权限不足");return map;}
      //  String parameter=object.get("parameter").toString();
     //   String app_sign=object.get("app_sign").toString();
      //  String app_pwd=Parameters.getParameters("app_pwd");
      //  String MD5app_sign=Md5Util.GetMD5Code(app_pwd+parameter+app_pwd);
        //System.out.println(app_pwd+parameter+app_pwd);
     //   System.out.println(MD5app_sign);
      //  System.out.println(app_sign);
     //   if(!app_sign.equals(MD5app_sign)){map.put("ret","1");map.put("code",20000);map.put("message","签名错误");return map;}
        map.put("ret","0");
        return map;
    }

    public static boolean checkParameter(JSONObject object , ArrayList<String> arrayList){
        boolean flag =false;
        for (String s:arrayList){
            if(object.containsKey(s)&&object.get(s)!=null && !"".equals(object.get(s))){
                flag = true;
            }else {
                flag = false;
                break;
            }
        }
        return flag;
    }


}